home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / A⁄ROSE / MCPMBƒ / MBTask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-27  |  4.5 KB  |  189 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    MBTask.c
  4. #
  5. #    Example of an A/ROSE task, to be linked with "MBosmain.c.o"
  6. #  and downloaded to a MCP card.
  7. #
  8. #  Registers itself with 
  9. #  object_name  "MBTask"  and
  10. #  type_name    "MBServer".
  11. #
  12. #    The "Exercise" application in this same folder will then find
  13. #  this task on a MCP card, and use it for parallel processing
  14. #  (if the "MCP" checkbox is checked).
  15. #
  16. #    Components:
  17. #                MBosmain.c
  18. #                iter16.a
  19. #                MBTask.c
  20. #
  21. ------------------------------------------------------------------------------*/
  22. /* -------------- MPW: select the following lines + <ENTER> ------
  23. Asm iter16.a
  24. C MBosmain.c
  25. C MBTask.c
  26. link -t 'DMRP' -c 'RWM ' ∂
  27.     MBosmain.c.o ∂
  28.     MBTask.c.o ∂
  29.     iter16.a.o ∂
  30.     ::OS.o ∂
  31.     ::osglue.o ∂
  32.     -o start
  33.     
  34. ::Download start
  35. ---------------------------------------------------------------- */
  36.  
  37.  
  38.  
  39. #define    MBCODE    2000
  40.  
  41. static    char    my_object_name [] = "MBTask";
  42. static    char    my_type_name []   = "MBServer";
  43.  
  44.  
  45.  
  46. // definitions from "os.h":
  47.  
  48. typedef long    tid_type;
  49.  
  50. struct mMessage
  51. {
  52.     struct    mMessage    *mNext;
  53.     long                mId;
  54.     short                mCode;
  55.     short                mStatus;
  56.     unsigned    short    mPriority;
  57.     tid_type            mFrom;
  58.     tid_type            mTo;
  59.     unsigned    long    mSData [3];
  60.     unsigned    long    mOData [3];
  61.     long                mDataSize;
  62.     char                *mDataPtr;
  63. };
  64.  
  65. typedef struct mMessage mMessage;
  66.  
  67. #define    OS_MATCH_ALL    0        // on receive match anything
  68. #define    OS_NO_TIMEOUT    0        // receive waits forever for message
  69.  
  70. // some #define's from "managers.h":
  71.  
  72. #define    OS_UNKNOWN_MESSAGE        (1<<8)    // unrecognized message code
  73. #define    Machine_Visible            0            // Register_task Machine visible flag
  74.  
  75.  
  76. // prototypes
  77.  
  78. void MBTask();
  79. void myBitSet(char *pixStorage, long i);
  80. extern pascal short ITER16(short cx, short cy, short nmax);
  81.  
  82. extern char        Register_Task(char *, char *, short);
  83. extern void        FreeMsg();
  84. extern mMessage *Receive(unsigned long, tid_type, unsigned short, long, ...);
  85. extern void        SwapTID(mMessage *);
  86. extern void        Send(mMessage *);
  87. extern char        *AROSEGetMem();
  88. extern void        AROSEFreeMem(char *);
  89. extern void        AROSEBlockMove();
  90. extern short    NetCopy(tid_type, void *, tid_type, void *, unsigned long);
  91.  
  92. pascal void illegal ()    extern    0x4afc;
  93.         
  94.         
  95. struct MBparms {
  96.     short        nmax;            // max. depth of iteration
  97.     short        d;                // corresponding to coord. distance between pixels
  98.     short        cx, cy;        // current point of the complex plane to be computed
  99.     short        yMCP;            // line number (to be sent back to server)
  100. };
  101.  
  102.  
  103.  
  104. //===============================
  105. void MBTask()
  106. //===============================
  107. {
  108.     struct MBparms MBp;        // these are the first 12 bytes of MBvariables, passed
  109.                                     // along in m->mSData[0..2];
  110.     short  pixcnt, i;
  111.     mMessage *m;
  112.     char     *pixStorage, *p;
  113.  
  114. // message sent by client:
  115. // mCode = MBCODE
  116. // mSData[0..1] = 8 bytes of MBparms (first 8 bytes of MBvariables in "Exercise")
  117.  
  118. // mDataSize = rowBytes     => suppose rowBytes * 8  pixels !
  119. // mDataPtr  = pointer to pixel line number MBp.cy of offscreen bitmap.
  120.  
  121. // server gets local memory for storage of computed pixels
  122. // does NetCopy of local values back to mDataPtr
  123.  
  124.     
  125.     if (!Register_Task (my_object_name, my_type_name, Machine_Visible))
  126.         illegal ();    // go debugging: something mysterious happens
  127.                     
  128.     while(1)     // forever !
  129.     {
  130.         m = Receive(OS_MATCH_ALL, OS_MATCH_ALL, OS_MATCH_ALL, OS_NO_TIMEOUT);
  131.          if (m->mStatus != 0)       // what happens?
  132.              FreeMsg(m);                  // I don't know: better get rid of it
  133.  
  134.         switch (m->mCode)    {
  135.  
  136.             case MBCODE:
  137.  
  138.                 AROSEBlockMove((char *)&m->mSData[0], (char *)&MBp, 12L);
  139.  
  140.                 pixcnt = 8 * m->mDataSize;
  141.                 p = AROSEGetMem(m->mDataSize);    // get local linebuffer each time
  142.                 if (p == 0) illegal ();                // (rather brutal error handling...)
  143.                 pixStorage = p;
  144.                 for (i=0; i<m->mDataSize; i++) *p++ = 0;
  145.                 for (i=0; i<pixcnt; i++) {
  146.                     if (ITER16(MBp.cx, MBp.cy, MBp.nmax) & 0x1)
  147.                         myBitSet(pixStorage, i);
  148.                     MBp.cx += MBp.d;
  149.                 }
  150.                     
  151.                 SwapTID(m);
  152.                 NetCopy(m->mFrom, pixStorage, m->mTo, m->mDataPtr, m->mDataSize);
  153.                 m->mCode++;            // send back the result
  154.                 m->mOData[0] = MBp.yMCP;
  155.                 Send (m);
  156.                 AROSEFreeMem(pixStorage);          // release local buffer each time
  157.  
  158.                 break;
  159.         
  160.             default:
  161.                 m->mCode |= 0x8000;    // unrecognized message code;
  162.                 m->mStatus = OS_UNKNOWN_MESSAGE;
  163.                 SwapTID(m);
  164.                 m->mCode++;
  165.                 Send (m);
  166.                 break;
  167.         } // switch
  168.     
  169.     }  // while (1)
  170.  
  171. }    // end MBTask()
  172.  
  173.  
  174.  
  175. //===============================
  176. void myBitSet(char *pixStorage, long i)
  177. //===============================
  178. {
  179.     long offset;
  180.     short bitnb;
  181.     char abyte, *p;
  182.     
  183.     offset = (i >> 3);  // divide /8
  184.     bitnb  = i - 8*offset;
  185.     abyte = 0x80 >> bitnb;
  186.     p = pixStorage + offset;
  187.     *p = *p | abyte;
  188. }
  189.